import { Global, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';
import configuration from 'config/configuration';
import { MysqlConfigService } from './services/mysqlConfig.service';
import { CommonService } from './services/common.service';
import { ParallercontrolService } from './services/parallercontrol.service';
@Global()
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: '.env',
      load: [configuration],
    }),
    TypeOrmModule.forRootAsync({
      inject: [MysqlConfigService],
      useFactory: (mysqlConfigService: MysqlConfigService) => {
        return {
          autoLoadEntities: true, // 自动加载所有的实体
          synchronize: true, // 保持代码和数据库的一致
          logging: false, // 输出内部真正执行的sql语句
          ...mysqlConfigService.mysqlConfig,
        };
      },
    }),
  ],
  exports: [MysqlConfigService, CommonService, ParallercontrolService],
  providers: [MysqlConfigService, CommonService, ParallercontrolService],
})
export class ShareModule {}
